<?php

class ListAndEditAction extends CAction {

	/**
	 * 模型
	 * Enter description here ...
	 * @var unknown_type
	 */
	public $modelName = '';
	public $pageSize;
	public $data = array();
	public $criteria = array();
	/**
	 * 成功提示语
	 * Enter description here ...
	 * @var unknown_type
	 */
	public $msg = '操作成功！';
	/**
	 * 成功跳转地址
	 * Enter description here ...
	 * @var unknown_type
	 */
	public $returnUrl;
	/**
	 * 页面
	 * Enter description here ...
	 * @var unknown_type
	 */
	public $view;
	
	public function run() {
		$c = $this->controller;
		$modelName = empty($this->modelName) ? $c->modelName : $this->modelName;
		$searchModel = new $modelName('search');
		$model = new $modelName;
		$criteria = $searchModel->getDbCriteria();
		$criteria->mergeWith(new CDbCriteria($this->criteria));
		$searchModel->unsetAttributes();
		if (isset($_GET[$modelName])) {
			$searchModel->attributes = $_GET[$modelName];
		}
		if (isset($_POST[$modelName])) {
			$model->attributes = $_POST[$modelName];
			if ($model->save()) {
				Yii::app()->user->setFlash(FLASH::RESULT_SUCCESS, $this->msg);
				$c->redirect($this->returnUrl);
			}
		}
		
		$c->render($this->view,array_merge($this->data, array(
			'data' => $searchModel->search(),
			'model' => $model,
			''
		)));
	}
	
}

?>